package com.hucc.api.controller;

import com.alibaba.fastjson.JSON;
import com.hucc.api.domain.exceptions.BusinessException;
import com.hucc.api.domain.req.GroupReq;
import com.hucc.api.domain.res.ApiResult;
import com.hucc.api.service.GroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api("项目相关接口")
@RestController
@RequestMapping("/group")
public class GroupController {

    @Autowired
    GroupService groupService;


    @ApiOperation(value = "添加分组", notes="添加分组描述")
    @PostMapping("add")
    public ApiResult<Void> add(@RequestBody GroupReq groupReq) {

        try {
            groupService.add(groupReq);
            return ApiResult.success();
        } catch (BusinessException e) {
            log.error("add group error, projectReq: {}", JSON.toJSONString(groupReq), e);
            return ApiResult.fail(e.getMessage());
        } catch (Exception e) {
            log.error("add group error, projectReq: {}", JSON.toJSONString(groupReq), e);
            return ApiResult.fail("添加分组失败");
        }
    }
}
